package com.thkj.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.thkj.entity.TblVersion;
import com.thkj.service.TblVersionService;
import com.thkj.util.RequestUtil;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import dp.R;
import dp.dao.PagingList;
import com.thkj.framework.base.BaseController;

@RestController
@RequestMapping("/backstage/version")
public class VersionAction extends BaseController {
    @Autowired
    TblVersionService tblVersionService;
    
    @RequestMapping("")
    public ModelAndView index(){
    	return new ModelAndView("version/list");
    }
	
	@RequestMapping("/query")
    public R query(HttpServletRequest request, int page, int size){
    	Map<String, Object> param = RequestUtil.getParameterMap(request);
    	PagingList<TblVersion> list = tblVersionService.query(page, size, param);
    	return R.success(list);
    }
	
    @RequestMapping("/edit")
    public R edit(TblVersion tblVersion){
    	try {
    		if(StrUtil.isBlank(tblVersion.getId())) {
    			tblVersion.setId(IdUtil.objectId());
    			tblVersionService.insertTblVersion(tblVersion);
        	}else {
        		tblVersionService.updateTblVersion(tblVersion);
        	}
        	return R.SUCCESS;
    	}catch (Exception e) {
			return R.failure(e.getMessage());
		}
    }
}